package com.wdl.modules.myhouse.controller;

import com.wdl.modules.myhouse.common.Result;
import com.wdl.modules.myhouse.dto.IconsDTO;
import com.wdl.modules.myhouse.entity.IconsEntity;
import com.wdl.modules.myhouse.service.IconsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * 我的图标库
 *
 * @author lucain sunlightcs@gmail.com
 * @since 1.0.0 2022-09-13
 */
@RestController
@RequestMapping("/icons")
@Api(tags = "我的图标库")
public class IconsController {
    @Autowired
    private IconsService iconsService;

    @GetMapping("/allIcons")
    @ApiOperation("所有图标")
    public Result<List<IconsDTO>> allIcons() {
        List<IconsEntity> icons = iconsService.list();
        List<IconsDTO> iconsDtos = new ArrayList<IconsDTO>();
        if (icons != null) {
            iconsDtos = icons.stream().map(en -> {
                IconsDTO dto = new IconsDTO();
                BeanUtils.copyProperties(en, dto);
                return dto;
            }).collect(Collectors.toList());
        }
        return new Result<List<IconsDTO>>().ok().setData(iconsDtos);
    }


}